﻿using UnityEngine;
using System.Collections;
using ui;

public class ScoreCollision : MonoBehaviour {

	// Use this for initialization
	private static int lastScoreCollidor = -1;

	public static void  init()
	{
		ScoreCollision.lastScoreCollidor = -1;
		SessionData.startSession();
	}

	void Start () 
	{

	}
	
	// Update is called once per frame
	void Update () 
	{
	
	}

	void OnTriggerEnter2D(Collider2D collision)
	{
		Debug.Log("Collision");
		GameObject gameObj =  collision.gameObject;
		if(gameObj.tag == "Player")
		{
			Debug.Log("Collision");
			int currentScoreGiven = int.Parse(this.gameObject.name);
			Debug.Log(this.gameObject.name + ""  +currentScoreGiven);
			if(currentScoreGiven > lastScoreCollidor)
			{
				updateScore();
				lastScoreCollidor = currentScoreGiven;
			}
		}
	}

	private void updateScore()
	{
		SessionData.score++;
		UiManager.updateScore(SessionData.score.ToString());
	}
}
